package com.sparrow.manage.user;

import com.sparrow.config.EnvironmentVariables;
import com.sparrow.manage.common.controller.StandardController;
import com.sparrow.manage.common.entity.result.Result;
import com.sparrow.manage.common.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(EnvironmentVariables.MANAGE_ACCESS_PREFIX + "/user")
public class UserController extends StandardController<User> {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @RequestMapping("index")
    public String index(){
        return EnvironmentVariables.MANAGE_TEMPLATE_STORE_PATH + "user/index";
    }

    @RequestMapping("addPage")
    public String addPage(){
        return EnvironmentVariables.MANAGE_TEMPLATE_STORE_PATH + "user/add";
    }

    @RequestMapping("editPage")
    public String editPage(){
        return EnvironmentVariables.MANAGE_TEMPLATE_STORE_PATH + "user/edit";
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(User user){
       return this.addEntity(user);
    }

    @ResponseBody
    @RequestMapping("delete")
    public Result delete(String id){
        return this.removeEntity(id);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(User user){
        return this.updateEntity(user);
    }

    @Override
    protected BaseService getService() {
        return userService;
    }

    @Override
    protected Result argumentsValidate(User user) {
        return null;
    }
}
